package Job;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;

/**
 * description:
 * author:zcx
 * lenovo
 * 时间：2022.02.08.11.33
 */
public class J7 {
    AtomicInteger num=new AtomicInteger(0);
    ReentrantLock lock=new ReentrantLock(true);
    void  work(){
        String tn=Thread.currentThread().getName();
        while (true) {
            lock.lock();
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.printf("%s%d  ", tn, num.incrementAndGet());
            if ("C".equals(tn)) {
                System.out.println();
            }
            lock.unlock();
        }
    }
    public static void main(String[] args) throws InterruptedException {
        var t=new J7();
        var a=new Thread(t::work,"A");
         a.start();
        var b=new Thread(t::work,"B");
        b.start();
        var c=new Thread(t::work,"C");
        c.start();


    }
}
